import streamlit as st

from api.redbook.text_api import generation_to_redbook

# 首先侧边栏
with st.sidebar:
    st.title("➡️欢迎使用我的AI应用")
    key = st.text_input("请输入通义大模型的密钥：")
    # key获取跳转链接
    st.page_link(
        "https://bailian.console.aliyun.com/?spm=5176.28326591.0.0.40f76ee1vUR5Of&accounttraceid=d873c9fe82ea443d9f3170f30dd5690cfnng#/api_key",
        label="无key？请点我获取", icon="🌎")

st.title("📖自行车小红书爆款文案生成器")
name = st.text_input("请输入自行车名称:")
temperature = st.slider("请调整大模型随机性:",step=0.1,min_value=0.0,max_value=1.0,value=0.5)
flag = st.button("文案生成")

if flag :
    if not key:
        st.info("请输入大模型密钥")
        st.stop()
    if not name:
        st.info("请输入自行车名称")
        st.stop()
    with st.spinner("AI正在思考，请稍等"):
        search_content,redbook = generation_to_redbook(key,temperature,name)
        st.divider()
        col1,col2 = st.columns(2)
        with col1:
            titles = redbook.title
            index = 0
            for title in titles:
                index += 1
                st.markdown(f"## 小红书爆款标题{index}")
                st.write(title)
        with col2:
            st.markdown("## 小红书爆款正文:")
            st.write(redbook.content)
        st.divider()
        with st.expander("借鉴内容来源"):
            st.write(search_content)


